package org.saratogaschools.edd.firefighter.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;

public class SelectRoleView extends Composite {

	public interface Presenter {

		void registerAsChief();

		void registerAsFighter();

	}

	private static SelectRoleViewUiBinder uiBinder = GWT
			.create(SelectRoleViewUiBinder.class);

	interface SelectRoleViewUiBinder extends UiBinder<Widget, SelectRoleView> {
	}

	private Presenter presenter;
	
	@UiField
	RadioButton chiefButton;
	
	@UiField
	RadioButton fighterButton;
	
	@UiField
	Button registerButton;

	public SelectRoleView() {
		initWidget(uiBinder.createAndBindUi(this));
		fighterButton.setValue(true);
	}

	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@UiHandler("registerButton")
	void onRegisterButtonClicked(ClickEvent evt) {
		registerButton.setEnabled(false);
		if (chiefButton.getValue()) {
			presenter.registerAsChief();
		}
		else {
			presenter.registerAsFighter();
		}
	}

	public void setChiefRegistrationEnabled(boolean chiefEnabled) {
		chiefButton.setEnabled(chiefEnabled);
	}

}
